﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CrystalCore.Libs;
using Microsoft.Xna.Framework;
using Ivory;
using Microsoft.Xna.Framework.Input;
using CrystalCore.AI;

namespace CrystalCore.Libs
{
    public sealed class GameCamera : Camera
    {
        //Fields
        /// <summary>
        /// Set: Use the TagTo(...) function
        /// </summary>
        public IPathableEntity ActorToFollow { get; private set; }
        public Vector3 OffsetFromActor { get; set; }

        //cTor
        public GameCamera(Game game, Vector3 actorOffset, IPathableEntity Actor) 
            : base(game, -Vector3.One, Vector3.Zero)
        {
            TagTo(Actor);
            this.OffsetFromActor = actorOffset;
        }

        //Methods
        public override void UpdateCamera(InputControl input, GameTime time)
        {
            this.CameraLookAt = ActorToFollow.EntityPosition;
            this.CameraPosition = ActorToFollow.EntityPosition + OffsetFromActor;

            float rotateY = 0f;
            if (input.IsKeyDown(Keys.Left) || input.IsKeyDown(Keys.A))
                rotateY += (0.01f * 3f);
            else if (input.IsKeyDown(Keys.Right) || input.IsKeyDown(Keys.D))
                rotateY -= (0.01f * 3f);
        }

        public void TagTo(IPathableEntity entity)
        {
            this.ActorToFollow = entity;
        }
    }
}
